<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"/>
	<title>添加</title>
	<style>
		h4{
			margin:8px 0px;
		}
		.inp{
			outline:none;
			padding-left:10px;
			border:1px solid #ccc;
			border-radius:3px;
			width:95%;
			height:30px;
		}
		.btn-area{
			padding-top:20px;
			display:flex;
		}
		button{
			display:flex;
			width:70px;
			height:30px;
			justify-content:center;
			align-items:center;
			margin-right:10px;
			border:0px;
			outline:none;
			color:white;
			border-radius:3px;
		}
		#confirm{
			background:#26ABEC;
		}
		#cancel{
			background:#ccc;
		}
		.select-normal{
			width:140px;
			height:30px;
		}
	</style>
</head>
<body>
	<div style="padding:0px 15px;">
		<h4>上级模块</h4>
		<div>
			<select name="top_id" id="top_id" class="select-normal">
				<option value="">--请选择--</option>
				{foreach name="menu" item="item"}
				<option value="{$item.id}">{$item.name}</option>
				{/foreach}
			</select>
		</div>
		<h4>方法名称</h4>
		<div>
			<select name="action_name" id="action_name" class="select-normal">
				<option value="">--请选择--</option>
				{foreach name="action" item="val"}
				<option value="{$val.action_name}">{$val.action_name}</option>
				{/foreach}
			</select>
		</div>
		<h4>是否显示</h4>
		<div>
			<select name="is_show" id="is_show" class="select-normal">
				<option value="">--请选择--</option>
				<option value="1">显示</option>
				<option value="0">隐藏</option>
			</select>
		</div>
		<div class="btn-area">
			<button class="btn btn-primary" id="confirm">确定</button>
			<button class="btn btn-default" id="cancel">取消</button>
		</div>
	</div>

	{include file="common/page/jsfiles"}

	<script>
		//确认
		var stop=true;
		$("#confirm").click(function(){
			if(!stop){
				return;
			}
			var top_id=$("select[name=top_id]").val();
			var name=$("select[name=top_id]").find("option:selected").text();
			var action_name=$("select[name=action_name]").val();
			var is_show=$("#is_show").val();
			if(top_id && name && action_name && is_show){
				$.ajax({
					type:"post",
					url:"insertAction",
					data:{
						"top_id":top_id,
						"name":name,
						"action_name":action_name,
						"is_show":is_show,
					},
					dataType:"json",
					beforeSend:function(){
						index = layer.load(1, {
						  	shade: [0.1,'#fff'] //0.1透明度的白色背景
						});
						stop=false;
					},
					complete:function(){
						layer.close(index);
						stop=true;
					},
					success:function(res){
						if(res.errorCode==0){
							layer.msg("提交成功",{icon:1,time:1500},function(){
								parent.location.reload();
							})
						}
						else{
							layer.alert(res.errorInfo,{icon:2});
						}
					}
				})
			}
		})

		//关闭
		$("#cancel").click(function(){
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		})
	</script>
</body>
</html>